package com.xfatm.simplebrowser.util;

import android.app.Activity;

import java.util.HashMap;

/**
 * Created by wenjie on 2018/3/14.
 */

public class ActivityManageUtils {
    private static HashMap<String,Activity> activityHashMap=new HashMap<>();
    public static void addActivity(Activity activity){
        activityHashMap.put(activity.getClass().getName(),activity);
    }
    public static void finishActivity(Activity activity){
        activityHashMap.remove(activity.getClass().getName());
        activity.finish();
    }
    public static void setTopActivity(Activity activity){
        addActivity(activity);
        activityHashMap.put("topActivity",activity);
    }
    public static Activity getTopActivity(){
        return activityHashMap.get("topActivity");
    }
    public static void finishAll(){
        Activity top=getTopActivity();
        activityHashMap.remove("topActivity");
        activityHashMap.remove(top);
        for(Activity activity:activityHashMap.values()){
            activity.finish();
        }
        top.finish();
    }
}
